#!/bin/sh
#根据进程名杀死进程
if [ $# -lt 1 ]
then
  echo "缺少参数：process_name"
  exit 1
fi

cd /home/server/work/boomEGg/src

if [ $1 == "server" ]; then
    #检查Game服务器情况
	export GOPATH=/home/server/work/boomEGg
    GPsUser=server
    GPsName="gameServer"
    Gpid=`ps -ef |grep $GPsName|grep -v grep|grep -v vi|grep -v dbx\n |grep -v tail|grep -v start|grep -v stop |sed -n 1p |awk '{print $2}'`

    echo $Gpid
    if [ $Gpid ]; then
        kill -9 $Gpid
        echo "关闭程序:Game Server--${Gpid}"
        sleep 1
    fi

    go install game-server
    cd /home/server/work/boomEGg/bin
	mv game-server gameServer
    ./gameServer&
    echo "启动程序:server"
fi

if [ $1 == "web" ]; then
    #检查Web服务器情况
    WPsUser=gameserver
    WPsName=platform
    Wpid=`ps -u $WPsUser|grep $WPsName|grep -v grep|grep -v vi|grep -v dbx\n |grep -v tail|grep -v start|grep -v stop |sed -n 1p |awk '{print $1}'`

    if [ $Wpid ]; then
        kill -9 $Wpid
        echo "关闭程序:Web Server--${Wpid}"
        sleep 0.5
    fi

    #cd /home/gameserver/leafServer/src/platform
    go install platform
    ./platform&
    echo "启动程序:platform"
fi
